package office.excel.poi.exp;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;


public class LoadExcel {
 /**
   * Excel模板路径
   */
 public static String ExcelTemplatePath;
 /**
  * Excel模板名称
  */
 public static String ExcelTemplateName;
 /**
  * 生成的Excel名称
  */
 public static String NewExcelPath;
 /**
  * 生成的Excel保存路径
  */
 public static String NewExcelName;
 /**
  * Excel基路径
  */
 public static String basePath=getClassPath();
/**
 * 加载Excel模板
 * @return
 */
public static File loadExcelTemplate()
{
	String path = basePath+ExcelTemplatePath+ExcelTemplateName;
	File f = new File(path);
	if(f.exists()) return f;
    return null;
}

/**
 * 创建新的Excel
 * @return
 */
public static File createNewExcel()
{
	String path = basePath+NewExcelPath+NewExcelName;
	File f = new File(path);
	if(!f.exists())
	{
		createNewExcel(basePath+NewExcelPath,NewExcelName);
	}
	return f;
}
/**
 * 得到当前类的基路径
 * @return
 */
private static String getClassPath()
{
    String p = LoadExcel.class.getResource("/").getPath();
    p = p.substring(0, p.lastIndexOf("WEB-INF")-1);
    p = p.substring(p.indexOf("/")+1, p.length());
    p = p.replaceAll("/", "\\\\");
    return p;
}

@SuppressWarnings("unused")
private static void createNewExcel(String path,String name) 
{
	  HSSFWorkbook wb = null;
	try {
		File file = new File(path+name);
		if(file.exists())file.delete();
		wb = new HSSFWorkbook(new FileInputStream(file));
	} catch (IOException e) {
		e.printStackTrace();
	}  
     
}


}
